<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>checkregister</title>
    <link rel="stylesheet" href="/static/lib/css/layui.css" media="all">
</head>

<body>

    <blockquote class="layui-elem-quote layui-text">
        注意: 必须首先指定某个班级 每次签到以创建时间区分
    </blockquote>

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
        <legend>查看签到情况</legend>
    </fieldset>

    <!-- <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script> -->

    <form class="layui-form layui-form-pane" action="" lay-filter="">

        <div class="layui-form-item">
            <label class="layui-form-label">选择班级</label>
            <div class="layui-input-inline">
                <select name="classname" lay-verify="required" lay-search="" lay-filter="chooseclass" id='chooseclass'>
                    <option value="">请联系老师加入新班级</option>
                    {% for class in classes %}
                    <option value="{{ class.id }}">{{ class.classname }}</option>
                    {% endfor %}
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="demoTable" style="margin-top: 15px;">
                签到结果：
                <div class="layui-inline">
                    <select id='search_sid'>
                        <option value=""></option>
                        <option value="未签到">未签到</option>
                        <option value="出勤">出勤</option>
                        <option value="请假">请假</option>
                        <option value="旷课">旷课</option>
                    </select>
                </div>
                <button type="button" class="layui-btn" data-type="reload">搜索</button>
                <table class="layui-hide" id="LAY_table_user" lay-filter="user"></table>
            </div>
        </div>

    </form>

    <script src="/static/lib/layui.js" charset="utf-8"></script>
    <script src="/static/lib/axios.min.js"></script>
    <script>
        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate
                , $ = layui.$
                , table = layui.table;

            var $ = layui.$, active = {
                reload: function () {
                    var search_sid = $('#search_sid'); // 获取搜索内容
                    var chooseclass = $('#chooseclass')
                    //执行重载
                    table.reload('reload_table', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        , where: {
                            classid: chooseclass.val(),
                            result: search_sid.val(),
                        }
                        , url: '../api/register'
                    });
                }
            };

            $('.demoTable .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

            form.on('select(chooseclass)', function (data) {
                console.log(data.value); //得到被选中的值
                classid = data.value
                table.render({
                    elem: '#LAY_table_user'
                    , url: '../api/register?classid='+classid
                    , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                    , defaultToolbar: ['filter', 'exports', 'print']
                    , cols: [[
                        { field: 'id', title: 'ID', width: 80, sort: true, fixed: 'left' }
                        , { field: 'student_id', title: '学生id', width: 95, sort: true }
                        , { field: 'class_id', title: '班级id', width: 95, sort: true }
                        , { field: 'create_time', title: '发起时间', sort: true, width: 160 }
                        , { field: 'time', title: '签到时间', sort: true, width: 160 }
                        , { field: 'result', title: '结果', width: 90, fixed: 'right', sort: true }
                    ]]
                    , page: true
                    , id: 'reload_table'
                    , height: 'ful-400'
                });
            });

        });
    </script>

</body>

</html>